package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.actionform.CarPendingLiftActionForm;
import com.tianqu.tms.www.car.controller.CarSeniorManagementConfirmController;
import com.tianqu.tms.www.car.viewhelper.CarPendingLiftViewHelper;

/**
 * @author mufeiyu
 * 高级管理 - 信息查看action
 */
public class CarSeniorManagementConfirmAction extends TmsAction {
	private Logger logger = Logger.getLogger(CarSeniorManagementConfirmAction.class);
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");

		CarPendingLiftActionForm registerForm = (CarPendingLiftActionForm) uc.getInputForm();
		if("1".equals((String)uc.getAttribute("modifyFlag"))){
			if(StringUtil.isNullOrBlank(registerForm.getMemId())&&StringUtil.isNullOrBlank(registerForm.getMemberName())){
				String[] param = {"商户名称"};
				setErrorsToRequest(request, TmsConstants.U0005, param); // 商户名称必须输入
				return mapping.getInputForward();	
			}
			if (StringUtil.isNullOrBlank(registerForm.getMemId())&&!StringUtil.isNullOrBlank(registerForm.getMemberName())){
				setErrorsToRequest(request, TmsConstants.U0039, null); // 查询结果不存在
				return mapping.getInputForward();
			}
		}

		CarSeniorManagementConfirmController controller = new CarSeniorManagementConfirmController();
		controller.execute(uc);
		//
		CarPendingLiftViewHelper viewhelper = new CarPendingLiftViewHelper();
		viewhelper = (CarPendingLiftViewHelper) uc.getAttribute(TmsConstants.VIEWHELP);
		if ("禁用".equals(viewhelper.getMemStatus())){
			setErrorsToRequest(request, TmsConstants.U8017, null); // 当前商户帐号被禁用，不能进行任何操作。
		}

		request.setAttribute(TmsConstants.VIEWHELP, viewhelper);

		// 去掉缓存
		if (!StringUtil.isNullOrBlank((String)uc.getAttribute("modifyFlag"))) {
			uc.removeAttribute("modifyFlag");
		}
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}